/*! lzf */

var mapEnv = {
    init: function (a, t, n, e, i, o) {
        this.map || (this.baidu_key = i, this.plng = t, this.plat = n, this.map = new BMap.Map(a, {enableMapClick: !1}), this.map.centerAndZoom(new BMap.Point(t, n), 15), this.map.addControl(new BMap.NavigationControl({type: BMAP_NAVIGATION_CONTROL_ZOOM})), this.map.disableInertialDragging(!0)), e && this.repository(e, t, n, "", o)
    }, repository: function (a, t, n, e, i) {
        var f = this, h = [], u = function (l, p, c, d, m) {
            keyword = l.shift();
            var a = "https://api.map.baidu.com/place/v2/search?query=" + keyword + "&filter=sort_name:distance|sort_rule:1&page_size=" + d + "&location=" + c + "," + p + "&scope=2&radius=2000&output=json&ak=" + f.baidu_key;
            $.post(a, null, function (a) {
                if (0 === a.status) {
                    var t = a.results;
                    if ("地铁" === keyword) for (var n = 0, e = t.length; n < e; n++) t[n].name = t[n].name + "（地铁站）";
                    if ("公交" === keyword) {
                        var i = [], o = [];
                        for (n = 0, e = t.length; n < e; n++) i[t[n].name] = t[n];
                        for (var s in i) if (i.hasOwnProperty(s)) {
                            var r = i[s];
                            o.push(r)
                        }
                        t = o
                    }
                    h = h.concat(t), 0 < l.length ? u(l, p, c, d, m) : m instanceof Function ? m(h) : f.populateView(h, keyword)
                }
            }, "jsonp")
        };
        u(a, t, n, e = e || 20, i)
    }, onListClick: function (a) {
        var t = $(a).attr("lng"), n = $(a).attr("lat"), e = new BMap.Point(t, n), i = $(a).attr("name"),
            o = $(a).attr("address");
        this.openInfoWindow(o, e, i)
    }, populateView: function (a, t) {
        var o = this, n = function () {
            var a = $(this).attr("lng"), t = $(this).attr("lat"), n = new BMap.Point(a, t), e = $(this).attr("name"),
                i = $(this).attr("address");
            o.openInfoWindow(i, n, e)
        };
        if (a) {
            var e, i = "", s = [];
            o.map.clearOverlays();
            var r = new BMap.Point(o.plng, o.plat),
                l = new MyLabel({point: r, className: "map-location", offsetX: "12.5", offsetY: "40"});
            this.map.addOverlay(l);
            for (var p = 0, c = a.length; p < c; p++) {
                var d = a[p], m = p + 1, f = new BMap.Point(d.location.lng, d.location.lat);
                if (i += '<li onclick="mapEnv.onListClick(this);" data-num="' + m + '" address="' + d.address + '" lng="' + d.location.lng + '" lat="' + d.location.lat + '" name="' + d.name + '"><span class="conNum map-label' + m + '"></span><span class="conName">' + d.name + '</span><span class="conDis">' + d.detail_info.distance + "米</span></li>", e = new MyLabel({
                    point: f,
                    className: "map-mark" + m,
                    offsetX: "10.5",
                    offsetY: "33",
                    num: m
                }), o.map.addOverlay(e), e._div.setAttribute("lng", d.location.lng), e._div.setAttribute("lat", d.location.lat), e._div.setAttribute("name", d.name), e._div.setAttribute("address", d.address), e._div.onclick = n, s.push(f), 20 === p) break
            }
        }
        var h = o.map.getViewport(s, {enableAnimation: !0, margins: [10, 10, 10, 10]});
        switch (o.map.centerAndZoom(h.center, h.zoom), t) {
            case"地铁":
            case"公交":
                $("#subwayCon").html(i);
                break;
            case"美食":
            case"餐饮":
                $("#foodCon").html(i);
                break;
            case"购物":
            case"银行":
                $("#shopCon").html(i);
                break;
            case"学校":
            case"酒店":
                $("#educateCon").html(i)
        }
    }, openInfoWindow: function (a, t, n) {
        var e = {width: 300, title: "<strong>" + n + "</strong>", offset: new BMap.Size(0, -30), enableMessage: !0},
            i = new BMap.InfoWindow('<span style="color:#666; font-size:12px;">' + a + "</span>", e);
        this.map.openInfoWindow(i, t)
    }
};
!function () {
    var a = $("#map_aside");
    a.find(".tab").click(function () {
        a.find(".tabactive").removeClass("tabactive"), a.find(".tabCon ul").addClass("none"), $(this).addClass("tabactive"), $($(this).attr("data-link")).removeClass("none")
    })
}();